﻿using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using WimClipboard.MVVM;

namespace WimClipboard
{
    public class MainWindowViewModel : INotifyPropertyChanged
    {
        private ClipboardMonitor clipboardMonitor = new ClipboardMonitor();

        public MainWindowViewModel()
        {
            this.clipboardMonitor.ClipboardContentChanged += this.OnClipboardContentChanged;
            this.ClearClipboard = new DelegateCommand(this.ExecuteClearClipboard);
        }

        private void OnClipboardContentChanged(object sender, ClipboardDataEventArgs e)
        {
            this.NotifyPropertyChange("DataObject");
        }

        public string[] DataObjectFormats
        {
            get { return Clipboard.GetDataObject().GetFormats(); }
        }

        #region Clear Clipboard Command

        public ICommand ClearClipboard { get; private set; }

        private void ExecuteClearClipboard(object toto)
        {
            Clipboard.Clear();
        }

        #endregion Clear Clipboard Command

        #region INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;

        protected void NotifyPropertyChange(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion INotifyPropertyChanged
    }
}